package com.szhuang.mobilesafe.activity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;

/**
 * Created by szhuang on 2015/3/24.
 */
public abstract class GestureDetectorActivity extends Activity{

    protected GestureDetector gestureDetector;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        gestureDetector=new GestureDetector(this,new GestureDetector.SimpleOnGestureListener(){

            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                if((Math.abs(e1.getRawY()-e2.getRawY())>100)||(Math.abs(velocityX)<50)){

                    return true;
                }
                if(e2.getRawX()-e1.getRawX()>200){
                    previousStep();
                }

                if(e1.getRawX()-e2.getRawX()>200){
                    nextStep();
                }
                return super.onFling(e1, e2, velocityX, velocityY);
            }
        });
    }

    public abstract void previousStep();
    public abstract void nextStep();

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        gestureDetector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }
}
